﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Windows;

namespace PrismProject01.ViewModels {
    public partial class WarningDialogViewModel : ObservableValidator, IDialogAware {
        #region 实现IDialogAware
        public DialogCloseListener RequestClose { get; set; }

        public bool CanCloseDialog() => true;

        public void OnDialogClosed() { }

        public void OnDialogOpened(IDialogParameters parameters) {
            if (parameters.ContainsKey("title"))
                Title = parameters.GetValue<string>("title");
            if (parameters.ContainsKey("dollar"))
                Dollar = parameters.GetValue<int>("dollar");
        }

        public string Title { get; set; } = "温馨提示";
        #endregion


        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(RMB))]
        private int _dollar;

        public int RMB => 8 * Dollar;

        [RelayCommand]
        private void Confirm() {
            DialogParameters parameters = new DialogParameters();
            parameters.Add("rmb", RMB);
            RequestClose.Invoke(parameters, ButtonResult.OK);
        }

        [RelayCommand]
        private void Cancel() {
            RequestClose.Invoke(ButtonResult.Cancel);
        }
    }
}
